﻿using System;

namespace StockLib
{
    /// <summary>
    /// 股票信息
    /// </summary>
    public class Stock
    {
        #region 代码数据
        public StockMarket Market { get; set; }     // 证券市场类型
        public StockType Type { get; set; } 		// 证券类型
        public string Code { get; set; } 			// 证券代码        
        public string Name { get; set; } 		    // 中文名称
        public string NameEn { get; set; } 		    // 英文名称
        public string ShortName { get; set; } 	    // 拼音简称
        public object Reserved1 { get; set; }
        public object Reserved2 { get; set; }
        public object Reserved3 { get; set; }

        public string CodeKey
        {
            get
            {
                return Market.ToString().ToUpper() + Code;
            }
        }

        public string KeyDaemon
        {
            get
            {
                return string.Format("{0} {1}", Code, Name);
            }
        }

        #endregion

        #region 行情数据
        public ReportData Report { get; set; }

        public int Time 					        // 交易时间
        {
            get
            {
                if (Report != null)
                    return Report.Time;

                return 0;
            }
        }

        public DateTime Date
        {
            get
            {
                return TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddSeconds(Time);
            }
        }

        public int Flag					            // 停牌标志
        {
            get
            {
                if (Report != null)
                    return Report.Flag;

                return 0;
            }
        }

        public float Close			                // 昨收（元）
        {
            get
            {
                if (Report != null)
                    return Report.Close;

                return 0;
            }
        }

        public float Open 		        // 今开（元）
        {
            get
            {
                if (Report != null)
                    return Report.Open;

                return 0;
            }
        }

        public float High 				// 最高（元）
        {
            get
            {
                if (Report != null)
                    return Report.High;

                return 0;
            }
        }

        public float Low 			    // 最低（元）
        {
            get
            {
                if (Report != null)
                    return Report.Low;

                return 0;
            }
        }

        public float New 			    // 最新（元）
        {
            get
            {
                if (Report != null)
                    return Report.New;

                return 0;
            }
        }

        public float Volume 		    // 成交量（股）
        {
            get
            {
                if (Report != null)
                    return Report.Volume;

                return 0;
            }
        }

        public float Amount				// 成交额（元）
        {
            get
            {
                if (Report != null)
                    return Report.Amount;

                return 0;
            }
        }

        public float[] BuyPrice
        {
            get
            {
                if (Report != null)
                    return Report.BuyPrice;

                return new float[5];
            }
        }

        public float[] BuyVolume
        {
            get
            {
                if (Report != null)
                    return Report.BuyVolume;

                return new float[5];
            }
        }

        public float[] SellPrice
        {
            get
            {
                if (Report != null)
                    return Report.SellPrice;

                return new float[5];
            }
        }

        public float[] SellVolume
        {
            get
            {
                if (Report != null)
                    return Report.SellVolume;

                return new float[5];
            }
        }

        public float Diff
        {
            get
            {
                if (New > 0 && Close > 0)
                    return New - Close;

                return 0;
            }
        }

        public float Amplitude
        {
            get
            {
                if (New > 0 && Close > 0)
                    return (New - Close) / New;

                return 0;
            }
        }

        public float BuySellDiff
        {
            get
            {
                float buyVolume = BuyVolume[0] + BuyVolume[1] + BuyVolume[2] + BuyVolume[3] + BuyVolume[4];
                float sellVolume = SellVolume[0] + SellVolume[1] + SellVolume[2] + SellVolume[3] + SellVolume[4];
                if (buyVolume > 0 && sellVolume > 0)
                    return (float)Math.Floor(buyVolume - sellVolume);

                return 0;
            }
        }

        public float BuySellRatio
        {
            get
            {
                float buyVolume = BuyVolume[0] + BuyVolume[1] + BuyVolume[2] + BuyVolume[3] + BuyVolume[4];
                float sellVolume = SellVolume[0] + SellVolume[1] + SellVolume[2] + SellVolume[3] + SellVolume[4];
                if (buyVolume > 0 && sellVolume > 0)
                    return 200 * buyVolume / (buyVolume + sellVolume) - 100;

                return 0;
            }
        }

        #endregion

        public float Pe
        {
            get
            {
                if (Eps != 0)
                {
                    if (New > 0)
                        return New / Eps;
                    else
                        return Close / Eps;
                }

                return 0;
            }
        }

        public float Pb
        {
            get

            {
                if (NetAssetPs != 0)
                {
                    if (New > 0)
                        return New / NetAssetPs;
                    else
                        return Close / NetAssetPs;
                }

                return 0;
            }
        }

        #region 财务数据
        public FinanceData Finance { get; set; }

        public int ReportDate                                  // 总资产
        {
            get
            {
                if (Finance != null)
                    return Finance.ReportDate;

                return 0;
            }
        }

        public int ReportType                                  // 
        {
            get
            {
                if (Finance != null)
                    return Finance.ReportType;

                return 0;
            }
        }

        public float ErateDollar                                  // 
        {
            get
            {
                if (Finance != null)
                    return Finance.ErateDollar;

                return 0;
            }
        }

        public float ErateHkDollar                                  // 
        {
            get
            {
                if (Finance != null)
                    return Finance.ErateHkDollar;

                return 0;
            }
        }

        // ★偿债能力
        public float RatioLiquidity			                // 流动比率
        {
            get
            {
                if (Finance != null)
                    return Finance.RatioLiquidity;

                return 0;
            }
        }
        public float RatioQuick                 			// 速动比率
        {
            get
            {
                if (Finance != null)
                    return Finance.RatioQuick;

                return 0;
            }
        }
        public float VelocityReceivables                    // 应收帐款周率
        {
            get
            {
                if (Finance != null)
                    return Finance.VelocityReceivables;

                return 0;
            }
        }

        // ★经营能力
        public float VelocityMerchandise                    // 存货周转率
        {
            get
            {
                if (Finance != null)
                    return Finance.VelocityMerchandise;

                return 0;
            }
        }
        public float MainIncome                             // 主营业务收入
        {
            get
            {
                if (Finance != null)
                    return Finance.MainIncome;

                return 0;
            }
        }
        public float CashPs             					// 每股净现金流量
        {
            get
            {
                if (Finance != null)
                    return Finance.CashPs;

                return 0;
            }
        }

        // ★盈利能力
        public float ProfitMargin                           // 主营业务利润率 %
        {
            get
            {
                if (Finance != null)
                    return Finance.ProfitMargin;

                return 0;
            }
        }
        public float NetAssetYield                          // 净资产收益率 %
        {
            get
            {
                if (Finance != null)
                    return Finance.NetAssetYield;

                return 0;
            }
        }

        // ★资本结构
        public int DateBegin				                // 上市日期 Format is YYYYMMDD
        {
            get
            {
                if (Finance != null)
                    return Finance.DateBegin;

                return 0;
            }
        }

        public float ShareCountTotal		                // 总股本
        {
            get
            {
                if (Finance != null)
                    return Finance.ShareCountTotal;

                return 0;
            }
        }

        public float ShareCountA            			    // 流通A股
        {
            get
            {
                if (Finance != null)
                    return Finance.ShareCountA;

                return 0;
            }
        }

        public float ShareCountB                		    // 流通B股
        {
            get
            {
                if (Finance != null)
                    return Finance.ShareCountB;

                return 0;
            }
        }
        public float ShareCountH                		    // 流通H股
        {
            get
            {
                if (Finance != null)
                    return Finance.ShareCountH;

                return 0;
            }
        }
        public float ShareCountNational             	    // 国有股
        {
            get
            {
                if (Finance != null)
                    return Finance.ShareCountNational;

                return 0;
            }
        }
        public float ShareCountCorp                         // 法人股
        {
            get
            {
                if (Finance != null)
                    return Finance.ShareCountNational;

                return 0;
            }
        }
        public float ProfitPsud                             // 每股未分配利润
        {
            get
            {
                if (Finance != null)
                    return Finance.ProfitPsud;

                return 0;
            }
        }
        public float Asset                                  // 总资产
        {
            get
            {
                if (Finance != null)
                    return Finance.Asset;

                return 0;
            }
        }
        public float RatioHolderRight                       // 股东权益比率
        {
            get
            {
                if (Finance != null)
                    return Finance.RatioHolderRight;

                return 0;
            }
        }
        public float RatioLongDebt                          // 长期负债率
        {
            get
            {
                if (Finance != null)
                    return Finance.RatioLongDebt;

                return 0;
            }
        }
        public float RatioDebt                              // 资产负债率
        {
            get
            {
                if (Finance != null)
                    return Finance.RatioDebt;

                return 0;
            }
        }

        // ★投资收益能力
        public float NetAssetPs                             // 每股净资产
        {
            get
            {
                if (Finance != null)
                    return Finance.NetAssetPs;

                return 0;
            }
        }
        public float NetAssetPsRegulate                     // 调整每股净资产
        {
            get
            {
                if (Finance != null)
                    return Finance.NetAssetPsRegulate;

                return 0;
            }
        }
        public float Eps                                    // 每股收益
        {
            get
            {
                if (Finance != null)
                    return Finance.Eps;

                return 0;
            }
        }
        public float EpsDeduct                              // 扣除后每股收益
        {
            get
            {
                if (Finance != null)
                    return Finance.EpsDeduct;

                return 0;
            }
        }
        public float NetProfit                              // 净利润
        {
            get
            {
                if (Finance != null)
                    return Finance.NetProfit;

                return 0;
            }
        }
        public float MainProfit                             // 主营业务利润
        {
            get
            {
                if (Finance != null)
                    return Finance.MainProfit;

                return 0;
            }
        }
        public float TotalProfit                            // 利润总额
        {
            get
            {
                if (Finance != null)
                    return Finance.TotalProfit;

                return 0;
            }
        }

        // ★增长率
        public float ProfitInc                              // 主营利润增长率%
        {
            get
            {
                if (Finance != null)
                    return Finance.ProfitInc;

                return 0;
            }
        }
        public float IncomeInc                              // 主营收入增长率%
        {
            get
            {
                if (Finance != null)
                    return Finance.IncomeInc;

                return 0;
            }
        }
        public float AssetInc                               // 总资产增长率%
        {
            get
            {
                if (Finance != null)
                    return Finance.AssetInc;

                return 0;
            }
        }

        // ★技术数据统计值
        public float YieldAverage                           // 平均收益率%
        {
            get
            {
                if (Finance != null)
                    return Finance.YieldAverage;

                return 0;
            }
        }
        public float YieldStddev                            // 收益标准差%
        {
            get
            {
                if (Finance != null)
                    return Finance.YieldStddev;

                return 0;
            }
        }
        public float Beite                                  // β值
        {
            get
            {
                if (Finance != null)
                    return Finance.Beite;

                return 0;
            }
        }
        #endregion
    }
}
